package com.ideal.frame.node.netty.client;

import com.ideal.frame.node.netty.NettyMsg;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;
import io.netty.util.CharsetUtil;

/**
 * Created by haoxy on 2018/10/17.
 * E-mail:hxyHelloWorld@163.com
 * github:https://github.com/haoxiaoyong1014
 * 客户端编码器
 */
public class NettyClientMsgEncode extends MessageToByteEncoder<NettyMsg> {
    @Override
    protected void encode(ChannelHandlerContext channelHandlerContext, NettyMsg msg, ByteBuf byteBuf) throws Exception {
        byteBuf.writeLong(msg.getNodeId());
        byteBuf.writeCharSequence(msg.getNodeName(), CharsetUtil.UTF_8);
        byteBuf.writeBytes(msg.getMessage().getBytes()) ;
    }
}
